package Game.Spawners;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.SlickException;

import Game.Level;
import Game.Items.Others.GIChestKey;
import Game.Objects.GOGoldChest;
import Game.Objects.GameObject;
import Game.Objects.GameObject.EGameObjectType;
import Game.Objects.Creatures.GOCreature;
import GameMath.GPoint;

/** Spawn Gold Chest class
 * @author Aikidos
 */
public class SpawnGoldChest extends SpawnerBase {

	@Override
	public void spawn(Level level) throws SlickException {
		if (!level.isUndergroundTown()) {
			// Create list of enemy creatures
			List<GOCreature> lstEnemyCreatures = new ArrayList<GOCreature>();
			List<GameObject> lstObjects = level.getObjectManager().getObjects();
			for (GameObject gameObject : lstObjects) {
				if (gameObject.isCreature()) {
					GOCreature creature = (GOCreature) gameObject;
					if (creature.Type == EGameObjectType.Enemy)
						lstEnemyCreatures.add(creature);
				}
			}

			// Spawn chest #1
			List<GPoint> banCoords = new ArrayList<GPoint>();
			banCoords.add(level.getObjectManager().getPlayer().getCoord());
			banCoords.add(level.getObjectManager().getObjectsByClass(
					"Game.Objects.GOLever")[0].getCoord());
			banCoords.add(level.getObjectManager().getObjectsByClass(
					"Game.Objects.GOTrapdoor")[0].getCoord());

			level.getObjectManager().spawnObject(
					new GOGoldChest(level.getObjectManager()), banCoords);

			// Add key to mob
			lstEnemyCreatures.get(0).getInventory()
					.addItem(new GIChestKey(), 1000);

			// Spawn chest #2
			banCoords.add(level.getObjectManager().getObjectsByClass(
					"Game.Objects.GOGoldChest")[0].getCoord());

			level.getObjectManager().spawnObject(
					new GOGoldChest(level.getObjectManager()), banCoords);

			// Add key to mob
			lstEnemyCreatures.get(1).getInventory()
					.addItem(new GIChestKey(), 1000);
		}
	}
	
}
